//判断是否在微信打开
function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
var ispcword="yes";//pc判断
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            ispcword="no";
            break;
        }
    }
    return flag;
}
IsPC();
//用户ID 全用cookie保存
var id=$.cookie("MYID");
var urlfrom=location.href;
if(id&&id!="undefined"){
    id=$.cookie("MYID");
}

if(localStorage.getItem("MYID")){
    id=localStorage.getItem("MYID");

    $.cookie("MYID",localStorage.getItem("MYID"));
}


if(document.getElementById("logo")){
    document.getElementById("logo").onclick=function(){

        location.href="http://www.pulu.com/weixin/pulu.html";
    };
}

//一级列表
if(document.getElementById("read1")){
    document.getElementById("read1").onclick=function(){
        $.cookie("readyourcurrentIndex","");
        $.cookie("readyourscrollTop","");

        location.href="fellower.html";
    };
};
if(document.getElementById("gotonews")){
    document.getElementById("gotonews").onclick=function(){
        $.cookie("readyourcurrentIndex","");
        $.cookie("readyourscrollTop","");
        if(ispcword=="yes"){
            location.href="http://www.pulu.com/weixin/homepc.html";
        }
        else{
            $.cookie("newstype","0");
            location.href="http://www.pulu.com/weixin/home.html";
        }
    };
};
if(document.getElementById("answer1")){
    document.getElementById("answer1").onclick=function(){
        $.cookie("pulupagepage","");//清除页面ID
        $.cookie("pulupagescroll","");//当前滚动距离
        $.cookie("pulupagepage","");//当前显示页面
        $.cookie("tjcurrentIndex","");//推荐数据页码
        $.cookie("zhncurrentIndex","");//召唤你数据页码
        $.cookie("jycurrentIndex","");//经验 铺路数据页码
        location.href="http://www.pulu.com/weixin/questionlistjy.html";
    };
}
if(document.getElementById("chat1")){
    document.getElementById("chat1").onclick=function(){
        $.cookie("comefrom","");//返回去除好友通知红点 新的好友页面
        $.cookie("friendotherpage","");//好友详情页返回定位锚
        location.href="chatpage.html";
    };
}
if(document.getElementById("set1")){
    document.getElementById("set1").onclick=function(){
        location.href="setpage.html";
    };
}
//-------------

if(document.getElementById("chat11")){
    document.getElementById("chat11").onclick=function(){
        location.href="chatpage.html";
    };
}
if(document.getElementById("set11")){
    document.getElementById("set11").onclick=function(){
        location.href="setpage.html";
    };
}
//只针对经验的跳转
if(!/sendexp/.test(location.href)){
    //1吃亏
    if(document.getElementById("chikui")){
        document.getElementById("chikui").onclick=function(){
            location.href="questionchikui.html";
        };
    }
//2划算
    if(document.getElementById("huasuan")){
        document.getElementById("huasuan").onclick=function(){
            location.href="questionhuasuan.html";
        };
    }
//3新奇
    if(document.getElementById("xinqi")){
        document.getElementById("xinqi").onclick=function(){
            location.href="questionxinqi.html";
        };
    }
//4电影
    if(document.getElementById("dianying")){
        document.getElementById("dianying").onclick=function(){
            location.href="questiondianying.html";
        };
    }
//5饭店
    if(document.getElementById("fandian")){
        document.getElementById("fandian").onclick=function(){
            location.href="questionfandian.html";
        };
    }
//6游玩
    if(document.getElementById("youwan")){
        document.getElementById("youwan").onclick=function(){
            location.href="questionyouwan.html";
        };
    }
//7书
    if(document.getElementById("shu")){
        document.getElementById("shu").onclick=function(){
            location.href="questionshu.html";
        };
    }
//其他
    if(document.getElementById("qita")){
        document.getElementById("qita").onclick=function(){
            location.href="http://www.pulu.com/weixin/questionqita.html";
        };
    }
//人生经历
    if(document.getElementById("rensty")){
        document.getElementById("rensty").onclick=function(){
            location.href="http://www.pulu.com/weixin/questionrensty.html";
        };
    }
//育儿经验
    if(document.getElementById("yejy")){
        document.getElementById("yejy").onclick=function(){
            location.href="http://www.pulu.com/weixin/questionye.html";
        };
    }
//工作经验
    if(document.getElementById("gzjy")){
        document.getElementById("gzjy").onclick=function(){
            location.href="http://www.pulu.com/weixin/questiongz.html";
        };
    }
//健康经验
    if(document.getElementById("jkjy")){
        document.getElementById("jkjy").onclick=function(){
            location.href="http://www.pulu.com/weixin/questionjk.html";
        };
    }
//购物经验
    if(document.getElementById("gwjy")){
        document.getElementById("gwjy").onclick=function(){
            location.href="http://www.pulu.com/weixin/questiongw.html";
        };
    }
}
//二级列表
if(document.getElementById("yours2")){
    document.getElementById("yours2").onclick=function(){
        $.cookie("readyourcurrentIndex","");
        $.cookie("readyourscrollTop","");
        if(ispcword=="yes"){
            location.href="http://www.pulu.com/weixin/homepc.html";
        }else{
            $.cookie("newstype","0");
            location.href="http://www.pulu.com/weixin/home.html";
        }
    };
}
//只在阅读圈 新闻列表有
if(document.getElementById("zhzx2")){
    document.getElementById("zhzx2").onclick=function(){
        $.cookie("newstype","1");
        if(ispcword=="yes"){
            location.href="http://www.pulu.com/weixin/zonghenews.html";
        }else{

            location.href="http://www.pulu.com/weixin/home.html";
        }
    };
}
if(document.getElementById("hyxw2")){
    document.getElementById("hyxw2").onclick=function(){
        $.cookie("newstype","2");
        if(ispcword=="yes"){
            location.href="http://www.pulu.com/weixin/zonghenews.html";
        }else{

            location.href="http://www.pulu.com/weixin/home.html";
        }
    };
}
if(document.getElementById("xq2")){
    document.getElementById("xq2").onclick=function(){
        $.cookie("newstype","3");
        if(ispcword=="yes"){
            location.href="http://www.pulu.com/weixin/zonghenews.html";
        }else{
            //history.go(-1);
            location.href="http://www.pulu.com/weixin/home.html";
        }
    };
}
if(document.getElementById("question1")){
    document.getElementById("question1").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlisttw.html";
    };
}
//高额经验跳转
if(document.getElementById("exphei")){
    document.getElementById("exphei").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlistjyg.html";
    }
}
//好友经验
if(document.getElementById("friexp")){
    document.getElementById("friexp").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlistjyf.html";
    }
}
//附近 经验 https
if(document.getElementById("expnear")){
    document.getElementById("expnear").onclick=function(){
        location.href="https://www.pulu.com/weixin/questionlistjnear.html";
    }
}
//问题跳转
if(document.getElementById("quebtn")){
    document.getElementById("quebtn").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlisttw.html";
    }
}
if(document.getElementById("quebtn2")){
    document.getElementById("quebtn2").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlisttw.html";
    }
}
//等待回答
if(document.getElementById("quewait")){
    document.getElementById("quewait").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlistwait.html";
    }
}
//附近 问题 https
if(document.getElementById("quenear")){
    document.getElementById("quenear").onclick=function(){
        location.href="https://www.pulu.com/weixin/questionlisttnear.html";
    }
}
//好友问题
if(document.getElementById("firque")){
    document.getElementById("firque").onclick=function(){
        location.href="http://www.pulu.com/weixin/questionlisttwf.html";
    }
}
//详细规则
if(document.getElementById("jyrulepage")){
    document.getElementById("jyrulepage").onclick=function(){
        location.href="questionlistjyrule.html";
    }
}
if(document.getElementById("twrulepage")){
    document.getElementById("twrulepage").onclick=function(){
        location.href="questionlisttwrule.html";
    }
}
//搜索框
if(document.getElementById("gotosearch")&&!/searchdetail/.test(location.href)){
    document.getElementById("gotosearch").onclick=function(){
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                //console.log("没有填信息")
            }else{
                location.href="searchdetail.html?searchKey="+word;
            }
        }
    };
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // enter 键
            var word=document.getElementById("searchinput").value;
            if(word){
                if(word.match(/^\s+$/g)){

                }else{
                    location.href="searchdetail.html?searchKey="+word;
                }
            }
        }
    };
}

//放大镜搜索按钮
if(document.querySelector(".header_action_buttons a.search")&&!/searchdetail/.test(location.href)){
    document.querySelector(".header_action_buttons a.search").onclick=function(){
        location.href="searchdetail.html?searchKey=";
    };
}

//发布跳转 经验
if(document.querySelector(".quick")){

    var quick=document.getElementsByClassName("quick")[0];
    quick.onclick=function(){
        if(is_weixn()){

            $.cookie("expkeyword","");
            $.cookie("expType","");
            $.cookie("sendque","");
            /questionchikui/.test(loca)?$.cookie("expType","chikui"):/questionhuasuan/.test(loca)?$.cookie("expType","huasuan"):/questionxinqi/.test(loca)?$.cookie("expType","xinqi"):/questiondianying/.test(loca)?$.cookie("expType","tuijiandy"):/questionfandian/.test(loca)?$.cookie("expType","tuijianfd"):/questionyouwan/.test(loca)?$.cookie("expType","youwan"):/questionshu/.test(loca)?$.cookie("expType","shu"):/questionqita/.test(loca)?$.cookie("expType","qita"):/questionjk/.test(loca)?$.cookie("expType","jkjy"):/questiongw/.test(loca)?$.cookie("expType","gwjy"):/questiongz/.test(loca)?$.cookie("expType","gzjy"):/questionye/.test(loca)?$.cookie("expType","yejy"):$.cookie("expType","");
            location.href="sendexpgpc.html";
        }
        else{

            eid="";
            var expType="";
            /questionchikui/.test(loca)?expType="&expType=chikui":/questionhuasuan/.test(loca)?expType="&expType=huasuan":/questionxinqi/.test(loca)?expType="&expType=xinqi":/questiondianying/.test(loca)?expType="&expType=tuijiandy":/questionfandian/.test(loca)?expType="&expType=tuijianfd":/questionyouwan/.test(loca)?expType="&expType=youwan":/questionshu/.test(loca)?expType="&expType=shu":/questionqita/.test(loca)?expType="&expType=qita":/questionye/.test(loca)?expType="&expType=yejy":/questiongz/.test(loca)?expType="&expType=gzjy":/questiongw/.test(loca)?expType="&expType=gwjy":/questionjk/.test(loca)?expType="&expType=jkjy":expType="";
            location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+eid+expType;
        }
    }
}
//问题
if(document.querySelector(".quick1")){
    var quick1=document.getElementsByClassName("quick1")[0];
    var placeholderword=["有什么烦恼解不开...","有什么困惑想不通...","有什么好奇的事..."];
    var num=parseInt(Math.random()*(3-1+1)+1);

    $(".quick1>div:last-child").html(placeholderword[num-1]);
    quick1.onclick=function(){
        if(is_weixn()){
            $.cookie("expkeyword","");
            $.cookie("sendque","question");
            location.href="http://www.pulu.com/weixin/sendexpgpc.html?sendque=question";
        }
        else{location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+"&sendque=question";}
    }
}

$("#quickexplist").click(function(e){
    if(e.target.id){

    }else{
        $("#quickexplist").css("display","none");
    }
});
$("body").css("min-height",window.screen.availHeight+"px");
//
if(document.querySelector(".HeaderSwitcher .inner")){
    document.querySelector(".HeaderSwitcher .inner").addEventListener("touchstart", touchStart, true);
    function touchStart(){
        $(".HeaderSwitcher .switcher .inner").css("overflow","auto");
        return;
    }
    document.querySelector(".HeaderSwitcher .inner").addEventListener("touchmove", "", true);
}